using Microsoft.WowAddonStudio.Lua.RuntimeService.Tests.Common;
using Microsoft.WowAddonStudio.Lua.RuntimeService.Tests.Mocks;
using Microsoft.WowAddonStudio.Lua.RuntimeService.WowBench;
using Microsoft.WowAddonStudio.Lua.RuntimeService.WowBench.Resolvers;
using NUnit.Framework;

namespace Microsoft.WowAddonStudio.Lua.RuntimeService.Tests.WowBench
{
	[TestFixture]
	public class WoWBenchCommandTest : WoWBenchTestBase
	{
		private IWoWBenchCommandHandler commandHandler;
		private ILuaRuntime runtime;

		#region SetUp

		[TestFixtureSetUp]
		public override void TestFixtureSetUp()
		{
			ConfigurationHelper.InitializeServiceLocator(Provider);
			runtime = new LuaRuntime(Provider, new ResolverFactory(Provider), new MockShellHostFactory());
			commandHandler = new WoWBenchController(runtime);
		}

		[SetUp]
		public override void SetUp()
		{
			base.SetUp();
		}

		#endregion

		#region TearDown

		[TearDown]
		public override void TearDown()
		{
			base.TearDown();
		}

		#endregion

		#region Tests

		[Test(Description = "")]
		public void Test_SimpleWoWBenchCommand()
		{
			const string commandText = "print(10)";
			var command = new WoWBenchCommand(commandHandler, commandText);
			Assert.AreEqual(command, command.Current);
			Assert.IsNull(command.Next);
			Assert.IsNull(command.Previous);
			Assert.IsNull(command.First);
			Assert.IsNull(command.Last);
			Assert.AreEqual(commandText, command.GetCommand());
			command.Clear();
			Assert.AreEqual(string.Empty, command.GetCommand());
		}

		[Test(Description = "")]
		public void Test_ComplexWoWBenchCommands()
		{
			const string commandText = "print(10)";
			ICommandEntry command = new WoWBenchCommand(commandHandler, ">print(10)");
			Assert.AreEqual(commandText, command.GetCommand());

			command.Add("cmd>print(10)");
			Assert.AreEqual(commandText, command.GetCommand());
			command.Add("debug>print(10)");
			Assert.AreEqual(commandText, command.GetCommand());
			command.Add("print(10 > 3)");
			Assert.AreEqual("print(10 > 3)", command.GetCommand());
			command.Add("print(10>3)");
			Assert.AreEqual("print(10>3)", command.GetCommand());
			command.Add("b = 10 >= 3");
			Assert.AreEqual("b = 10 >= 3", command.GetCommand());
			command.Add("b=10>=3");
			Assert.AreEqual("b=10>=3", command.GetCommand());
			command.Add("10>=3");
			Assert.AreEqual("10>=3", command.GetCommand());
			//command.Add(@"C:\>print(10)");
			//Assert.AreEqual(commandText, command.GetCommand());
			//command.Add(@"C:\Temp\>print(10)");
			//Assert.AreEqual(commandText, command.GetCommand());
		}

		#endregion
	}
}